<script type="text/javascript">
  function backPreviousPage()
  {
    window.history.back();
  }
</script>
<form class="form-horizontal" role="form" method="post" action="<?=site_url('user/edit/'.$user_id) ?>" enctype="multipart/form-data">  
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Tài khoản</label>
    <div class="col-sm-3">
      <input id="disabledInput" type="text" name="username" class="form-control" placeholder="Tài khoản" value="<?=$user->username; ?>" disabled>
      <span><?php echo form_error('username'); ?></span>
    </div>
  </div>  
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Tên đầy đủ</label>
    <div class="col-sm-3">
      <input id="codeInput" type="text" name="fullname" class="form-control" placeholder="Tên đầy đủ" value="<?=$user->fullname; ?>" required>
      <span><?php echo form_error('fullname'); ?></span>
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Website</label>
    <div class="col-sm-3">
      <input id="codeInput" type="text" name="website" class="form-control" placeholder="Website" value="<?=$user->website; ?>">
      <span><?php echo form_error('website'); ?></span>
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Mô tả</label>
    <div class="col-sm-3">
      <textarea id="form-control" name="desc" rows="3"><?=$user->desc ?></textarea>            
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Hình</label>
    <div class="col-sm-3">
    <?php 
      if(!empty($user->image))
      { 
        echo '<img src="'.base_url('uploads/image/designer/'.$user->image).'" alt="'.$user->fullname.'" class="img-thumbnail" style="width: 30%">';
      }
      else
      {
        echo '<img src="http://placehold.it/182x250" class="img-thumbnail" style="width: 60%">';
      }
    ?>
    </div>    
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Tải hình</label>
    <div class="col-sm-3">
      <input type="file" id="exampleInputFile" name="userfile">
      <p class="help-block"></p>
    </div>
  </div>     
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Email</label>
    <div class="col-sm-3">
      <input id="codeInput" type="text" name="email" class="form-control" placeholder="Email" value="<?=$user->email ?>" required>
      <span class="help-block"><?php echo form_error('email'); ?></span>
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Password</label>
    <div class="col-sm-3">
      <input id="codeInput" type="text" name="pass" class="form-control" placeholder="Cập nhật mật khẩu mới.." value="<?php echo set_value('pass'); ?>">
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Phân quyền</label>
    <div class="col-sm-3">
      <label class="checkbox-inline">
        <input type="checkbox" name="is_view" id="inlineCheckbox1" value="1" <?=!empty($user->is_view) ? 'checked' : '' ?>> Xem
      </label>
      <label class="checkbox-inline">
        <input type="checkbox" name="is_edit" id="inlineCheckbox2" value="1" <?=!empty($user->is_edit) ? 'checked' : '' ?>> Cập nhật
      </label>
    </div>
  </div>
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Kích hoạt</label>
    <div class="col-sm-3">
      <div class="checkbox">
        <label>
          <input type="checkbox" name="active" <?=!empty($user->active) ? 'checked' : '' ?> value="1">            
        </label>
      </div>
    </div>
  </div>  
  <div class="form-group">
    <label for="inputEmail3" class="col-sm-2 control-label">Xem thông tin đơn hàng</label>
    <div class="col-sm-3">
      <div class="checkbox">
        <label>
          <input type="checkbox" name="view_order" <?=!empty($user->view_order) ? 'checked' : '' ?> value="1">            
        </label>
      </div>
    </div>
  </div>
  <div class="form-group">
    <div class="col-sm-offset-2 col-sm-10">
      <button type="submit" name="updateBtn" value="updateBtnValue" class="btn btn-primary">Hoàn tất</button>
      <button type="button" name="backPrevBtn" value="goPrevious" class="btn btn-success" onclick="backPreviousPage()">Quay về trang trước</button>      
    </div>
  </div>    
</form>

<?php if(!empty($productDesigns)): ?>
<div class="page-header">
  <h1>Sản phẩm</h1>
</div>  
<div class="table-responsive">
  <table class="table table-bordered table-striped table-hover">
    <thead>
      <tr class="success" align="center">
        <td>Sản phẩm</td>               
        <td>Code</td>
        <td>Hình ảnh</td>
        <td>Giá</td>                    
        <td>Kích hoạt</td>            
        <td>Ngày tạo</td>   
        <td style="width:30%">Revenue</td>                           
      </tr>
    </thead>
    <tbody>      
      <?php 
        $i = 1;             
        foreach ($productDesigns as $row): 
          $product_image = !empty($row->image) ? '<img src="'.base_url('uploads/image/products/'.$row->image).'" class="img-responsive" style="width: 90%">' : '';

          $user_revenue = '';
          $price_revenue = '';

          if(!empty($user_revenuearr[$row->id]))
          {
            $user_revenue = $user_revenuearr[$row->id];
            $price_revenue = $user_revenue * $row->price / 100;
          }

          $active_tr = empty($row->active) ? 'class="danger"' : '';
          echo '<form role="form" action="'.site_url('user/updateRevenue/'.$row->id).'" method="post"
              <tr align="center" '.$active_tr.'>
              <td>'.$row->title.'</td>              
              <td>'.$row->code.'</td>
              <td style="width: 15%;">'.$product_image.'</td>
              <td>'.$row->price.'</td>
              <td>'.$row->active.'</td>
              <td>'.$row->created_at.'</td>
              <td style="width:30%">                
                <div class="row" align="center">
                  <div class="input-group col-sm-5">
                    <input type="text" name="revenue_'.$row->id.'" value="'.$user_revenue.'" class="form-control">
                    <span class="input-group-addon">%</span>
                  </div>
                  <br>
                  <button type="submit" name="updateBtn" value="updateBtnValue" class="btn btn-primary">Cập nhật</button>                                    
                  <br>
                  Giá Revenue: '.$price_revenue.'                  
                </div>
              </td>                            
              </tr></form>';               
          $i++;
        endforeach;
      ?>
    </tbody>
  </table>  
</div>  
<?php endif; ?>